package org.example;

import java.io.*;
import java.net.*;

/**
 * @author yuebo
 * @date 2025/6/16
 */
public class HttpDemo {

    public static void main(String[] args) throws IOException {
        testHttpGet();
    }

    private static void testHttpGet() throws IOException {
//        URL url = new URL("http://www.baidu.com/?test=hahaha");
        URL url = new URL("http://chenyuebo.cn/hello240/api/weather?cityCode=101010100");
        // 建立连接
//        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        // 建立连接，设置代理Proxy，可以用charles软件抓包
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)));
        // 读取服务器返回值
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }
        inputStream.close();
    }
}
